<?php

namespace App\Models;


class Campus extends Orm
{
    //
    protected $table = 'campus';
    protected $dateFormat = 'U';
    public $timestamps = true;
    protected $casts = [
        'line_pics' => 'json',
        'room_pics' => 'json'
    ];

    public function setLogoAttribute($value)
    {
        $this->dealSetImageAttribute('logo', $value);
    }

    public function setLinePicsAttribute($value)
    {
        $this->dealSetImageAttribute('line_pics', $value);
    }

    public function setRoomPicsAttribute($value)
    {
        $this->dealSetImageAttribute('room_pics', $value);
    }

    public function recommendMany()
    {
        return $this->hasMany(Recommend::class, 'campus_id', 'id')->where('status',1);
    }

    public function courseCanEnrollMany()
    {
        return $this->hasMany(Course::class, 'campus_id', 'id')->where('total', '>', 0)->where('valid',1)->where('start_time','>',time());
    }

    public function courseMany()
    {
        return $this->hasMany(Course::class, 'campus_id', 'id')->where('valid',1);
    }

}
